package com.Babysleep.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.Babysleep.R;
import com.Babysleep.manage.DanQuPlay;

public class DanQu extends PlayActivity {
	String name = null;
	private listener mylistener=new listener();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.danqu_page);
		init();
	}

	public void init() {
		((TextView) findViewById(R.id.introduce)).setText(getResources()
				.getText(getIntent().getIntExtra("string_id", 0)));

		findViewById(R.id.cycle).setOnClickListener(mylistener);
		findViewById(R.id.back_to_list).setOnClickListener(mylistener);
		findViewById(R.id.start).setOnClickListener(mylistener);
		get_file_name();
		System.out.println(name);
		player = new DanQuPlay(this);
		player.init((ImageButton) findViewById(R.id.start),name);
	}

	/**
	 * 根据不同的activity名获取文件名
	 */
	public void get_file_name() {

		switch (getIntent().getIntExtra("string_id", 0)) {
		case 0:
			name = "file:///android_asset/boli.mp3";
			break;
		case 1:
			name = "file:///android_asset/boli.mp3";
			break;
		case 2:
			name = "file:///android_asset/boli.mp3";
			break;
		case 3:
			name = "file:///android_asset/boli.mp3";
			break;

		default:
			break;
		}

		SharedPreferences setting = getSharedPreferences("settings", 0);
		name = setting.getString("song_name", null);
	}

	class listener implements OnClickListener {

		@Override
		public void onClick(View v) {
			visiblity_counter=300;
			switch (v.getId()) {
			case R.id.back_to_list:
				System.out.println(v.getId());
				back_to_list();
				break;
			case R.id.frame:
				Log.d("TAG", String.valueOf(v.getId()));
				break;
			case R.id.start:
				player.Play();
				break;
			case R.id.cycle:
				set_cycle();
				break;
			default:
				break;
			}
		}
	}

}
